package com.kang.controller;

import com.kang.entity.Reply;
import com.kang.service.ReplyService;
import com.kang.util.WebResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "评论接口")
@RequestMapping("/user/reply")
@Slf4j
public class ReplyController {

    @Autowired
    private ReplyService replyService;

    @ApiOperation("添加评论")
    @PostMapping("insertReply")
    public WebResponse insertReply(@RequestBody Reply reply,HttpServletRequest request) {
        try {
            return WebResponse.resSuccess("添加评论成功",replyService.insertReply(reply,request));
        } catch (Exception ex) {
            log.error("添加评论失败",ex);
            return WebResponse.resFail("添加评论失败",null);
        }
    }

    @ApiOperation("删除评论")
    @PostMapping("deleteReply")
    public WebResponse deleteReply(@RequestBody Reply reply) {
        try {
            return WebResponse.resSuccess("删除评论成功",replyService.deleteReply(reply.getId()));
        } catch (Exception ex) {
            log.error("删除评论失败",ex);
            return WebResponse.resFail("删除评论失败",null);
        }
    }

    @ApiOperation("查询评论")
    @GetMapping("getReplyList")
    public WebResponse getReplyList(Integer id) {
        try {
            return WebResponse.resSuccess("查询评论成功",replyService.getReplyList(id));
        } catch (Exception ex) {
            log.error("查询评论失败",ex);
            return WebResponse.resFail("查询评论失败",null);
        }
    }



}
